<template>
	<view class="tab">
		<scroll-view scroll-x="true" class="tab-scroll">
			<view class="tab-scroll_box">
				<view v-for="(item,index) in list" :key='index' class="tab-scroll-box_item"
					@click="clickTab(item,index)" :class="{active:activeIndex===index}">{{item.name}}</view>
			</view>
		</scroll-view>
		<view class="tab-icons" @click="openSet">
			<uni-icons type="gear" size="26" color="#666"></uni-icons>
		</view>

	</view>
</template>

<script>
	export default {
		name: "tab",
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			},
			tabIndex: {
				type: Number,
				default: 0
			}
		},
		watch: {
			tabIndex(newVal, oldVal) {
				this.activeIndex = newVal;
			}
		},
		data() {
			return {
				activeIndex: 0
			};
		},
		methods: {
			clickTab(item, index) {
				this.activeIndex = index;
				this.$emit('tab', {
					data: item,
					index: index
				})
			},
			openSet(){
				uni.navigateTo({
					url:'../../pages/home-label/home-label'
				})
			}
		}
	}
</script>

<style lang="scss">
	.tab {
		display: flex;
		width: 100%;
		border-bottom: 1px #f5f5f5 solid;
		background-color: #fff;
		box-sizing: border-box;

		.tab-scroll {
			flex: 1;
			overflow: hidden;
			box-sizing: border-box;
		}

		.tab-scroll_box {
			display: flex;
			flex-direction: row;
			height: 25px;
			flex-wrap: nowrap;
			align-items: center;
			box-sizing: border-box;

			.tab-scroll-box_item {
				flex-shrink: 0;
				padding: 0 10px;
				color: #333;
				font-size: 14px;

				&.active {
					color: $mk-base-color;
				}
			}
		}

		.tab-icons {
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>
